package trocabi.view;

import trocabi.TROCABI;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JTable;

public class JButtonCellEditor extends DefaultCellEditor {
    protected JButton button;
    public    JTableModelVenteArticles articlesModele;
    private ButtonListener bListener = new ButtonListener();

    public JButtonCellEditor(JCheckBox checkBox, JTableModelVenteArticles articlesModele) {
        super(checkBox); // TODO:????
        this.articlesModele=articlesModele;
        button = new JButton();
        button.setOpaque(true);
        button.addActionListener(bListener);
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        bListener.setRow(row);
        button.setText(value.toString());
        return button;
    }

    class ButtonListener implements ActionListener {
        private int row;
        private JButton button;

       public void setRow(int row) {
            this.row = row;
        }

        public JButton getButton() {
            return this.button;
        }

        @Override
        public void actionPerformed(ActionEvent event) {
            articlesModele.remove(row);
            this.button = ((JButton) event.getSource());
        }
    }
}
